from time import ctime, sleep


def test_func_with_paramter(level):
    """带参数的装饰器"""
    def decorator(func):
        def wrapper_func(*args, **kargs):
            if level=='warning':
                print('[%s] %s is called!!'%(ctime(), func.__name__))
            return func(*args)
        return wrapper_func
    return decorator
    
        
@test_func_with_paramter(level="warning")
def foo():
    pass

def test_func_no_paramter(func):
    """不带参数的装饰器"""
    def wrapper_func(*args, **kawargs):
        print('[%s] %s is called!!' % (ctime(), func.__name__))
        return func(*args)
    return wrapper_func

@test_func_no_paramter
def bar(name):
    print("hello, "+ name)

if __name__=="__main__":
    for i in range(10):
        sleep(1)
        foo()
    for i in range(10):
        sleep(1)
        bar("joe")
